//
//  InputView.m
//  IfengNews
//
//  Created by ifeng on 12-12-28.
//
//

#import "InputView.h"
#import "CLGloble.h"
#import "Sgr_macro.h"
//#import "Globle.h"
#import "UIButton+Create.h"
#import "CTCommentViewController.h"
#import "BUIControl.h"
#import "IFInputViewCell.h"
#import <MobileCoreServices/UTCoreTypes.h>
#import <AssetsLibrary/AssetsLibrary.h>
#import "UIView+Utils.h"

#define defaultHeight (168.f)
#define content_Background_Origin_Rect      CGRectMake(0, [CLGloble sharedInstance].globleHeight, 320.0f, 168.f)
#define content_Label_x       10.0f
#define content_Label_y       41.0f
#define content_Label_Width   300.0f//[Globle shareInstance].globleHeight - 150
#define content_Label_Height  62.0f

@interface InputView (){BOOL isUserClose;}@end

@implementation InputView
@synthesize commentContent,commentContentField;
@synthesize commentUpView,commentMidView,commentDownView,commentView;
@synthesize currentRowNum;
@synthesize delegate,backGroundButton;
@synthesize alertHeaderView,alertHeaderLabel,isReply;

- (void)canceleKeyboardNotifications
{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
    
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillChangeFrameNotification object:nil];
    
}

-(void)dealloc
{
    [self performSelector:@selector(canceleKeyboardNotifications)];
    
}



- (id)init
{
    self=[super init];
    if(self){
        self.isInOriginal=NO;
        self->isUserClose = NO;
        self.isShowLine=YES;
        self.name=@"评论";
        self.param=nil;
        self.successLine=@"您的评论在路上，稍后即到";
        self.isShowShare=NO;
        self.shareButtons=nil;
        //self.sharetype=noneType;
        _postparam = [NSMutableDictionary new];
        _liveparam = [NSMutableDictionary new];
    }
    return self;
}

#pragma mark -
#pragma mark - 键盘回收、弹出触发事件
//回收键盘操作
-(BOOL)resign{
    self->isUserClose = YES;
    if (iosVersion>=5.0) {
        if ([commentContent isFirstResponder]) {
            [commentContent resignFirstResponder];
            return YES;
        }
        else {
            [UIView animateWithDuration:0.25 animations:^{
                commentView.frame = CGRectMake(0, rect_m.origin.y, rect_m.size.width, commentView.height);
                self.backGroundButton.alpha = 0.0;
            } completion:^(BOOL finished) {
                [self performSelector:@selector(putCommentViewOriginal)];
                self.hidden = YES;
                [self removeFromSuperview];
            }];
        }
    }else
    {
        if ([commentContentField isFirstResponder]) {
            [commentContentField resignFirstResponder];
            return YES;
        }
    }
    return NO;
}

- (BOOL)resignWithRemoveView:(BOOL)isRemove
{
    self->isUserClose = isRemove;
    if (iosVersion>=5.0) {
        if ([commentContent isFirstResponder]) {
            [commentContent resignFirstResponder];
            return YES;
        }
    }else
    {
        if ([commentContentField isFirstResponder]) {
            [commentContentField resignFirstResponder];
            return YES;
        }
    }
    return NO;
}

-(void)notResign{
    self->isUserClose = NO;
    if (iosVersion>=5.0) {
        [commentContent becomeFirstResponder];
    }else
    {
        [commentContentField becomeFirstResponder];
    }
}

#pragma mark -
#pragma mark - 评论发送时的各种操作处理，提示框显示、隐藏
//创建顶部提示浮框
-(void)createalertHeaderView
{
    //初始化的提示浮框
    alertHeaderView = [[UIView alloc] initWithFrame:CGRectMake(10, 15+64, 299, 54)];
    alertHeaderView.backgroundColor = [UIColor clearColor];
    UIImageView *backgroundImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"comment_sendComment_alertBackGroung.png"]];
    backgroundImg.frame = CGRectMake(0, 0, alertHeaderView.frame.size.width, alertHeaderView.frame.size.height);
    [alertHeaderView addSubview:backgroundImg];
    alertHeaderLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, alertHeaderView.frame.size.width, alertHeaderView.frame.size.height)];
    alertHeaderLabel.backgroundColor = [UIColor clearColor];
    alertHeaderLabel.text = self.successLine;
    alertHeaderLabel.textAlignment = NSTextAlignmentCenter;
    alertHeaderLabel.textColor = [UIColor whiteColor];
    [alertHeaderView addSubview:alertHeaderLabel];
    [self addSubview:alertHeaderView];
    alertHeaderView.hidden = YES;
}
//显示顶部提示浮框
-(void)showAlertHeaderView:(NSString *)message
{
    if (!alertHeaderView) {
        [self createalertHeaderView];
    }
    if (NO==alertHeaderView.hidden && 1.0f == alertHeaderView.alpha) {
        return;
    }
    alertHeaderLabel.text = message;
    [self showView:alertHeaderView];
    [self performSelector:@selector(hiddenView:) withObject:alertHeaderView afterDelay:1.5];
}
-(void)showNetErrorAlert:(NSString *)message
{
    
    [[CLGloble sharedInstance] showTieAlertMessage:@"提示" subMessage:message];
}

-(void)showView:(UIView *)view
{
    view.hidden = NO;
    view.alpha = 0.0f;
    [UIView beginAnimations:@"fadeIn" context:nil];
    [UIView setAnimationDuration:0.3];
    view.alpha = 1.0f;
    [UIView commitAnimations];
    
}

-(void)hiddenView:(UIView *)view
{
    view.alpha = 1.0f;
    [UIView beginAnimations:@"fadeIn" context:nil];
    [UIView setAnimationDuration:0.3];
    view.alpha = 0.0f;
    [UIView commitAnimations];
}


-(void)issueComment:(NSString *)content{
    
    if(self.commentType==1){
        commentContent.text = @"";//清空
        commentContentField.text = @"";
        [self resign];
        
        return;
    }
    
    [_pickerButton setImage:[UIImage imageNamed:@"liveRoom_reporter_add_picker.png"] forState:UIControlStateNormal];
    
    BOOL isOnline = [[CLGloble sharedInstance] checkOnLine];
    if(!isOnline){
        [self showNetErrorAlert:@"发送失败,请检查网络连接"];
        return;
    }
    
    if ([(NSObject *)self.delegate respondsToSelector:@selector(postComment::)]) {//响应的这个
        [(NSObject *)self.delegate performSelector:@selector(postComment::) withObject:content withObject:@(self.beSelect)];
        
    }
    
    if ([(NSObject *)self.delegate respondsToSelector:@selector(postComment:param:)]) {
        if(self.param){
            if ([self.param isKindOfClass:[NSDictionary class]]) {
                [_postparam setDictionary:self.param];
            }
        }
        [self.delegate postComment:content param:_postparam];
    }
    
    if ([(NSObject *)self.delegate respondsToSelector:@selector(postComment:param:liveparam:)]) {
        if(self.param){
            if ([self.param isKindOfClass:[NSDictionary class]]) {
                [_postparam setDictionary:self.param];
            }
        }
        [self.delegate postComment:content param:_postparam liveparam:_liveparam];
    }
    
    self.param =nil;
    self.postparam=[NSMutableDictionary dictionary];
    _liveparam = [NSMutableDictionary dictionary];
    commentContent.text = @"";//清空
    commentContentField.text = @"";
    [self resign];
}

#pragma mark - uitextfield delegate
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{
    return YES;
}
- (BOOL)textViewShouldEndEditing:(UITextView *)textView{
    return YES;
}

- (void)textViewDidEndEditing:(UITextView *)textView{
    //  self.commentContent.frame = CGRectMake(2, 6, 316, 28);
    //  self.currentContent = textView.text;
}

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
    return YES;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    @synchronized(self){
        NSString *strWithoutSpcace =[textField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
        if (!strWithoutSpcace || 0 == [strWithoutSpcace length]) {
            [self showAlertHeaderView:@"评论内容为空"];
            return NO;
        }
        strWithoutSpcace = [strWithoutSpcace stringByReplacingOccurrencesOfString:@"<" withString:@" "];
        strWithoutSpcace = [strWithoutSpcace stringByReplacingOccurrencesOfString:@">" withString:@" "];
        strWithoutSpcace = [strWithoutSpcace stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
        if ([textField.text length] > 300) {
            [self showAlertHeaderView:@"您的内容不能多余300个字"];
            return NO;
        }
        [self performSelector:@selector(issueComment:) withObject:strWithoutSpcace];
        return  YES;
    }
    return YES;
}

#pragma mark - UITextView Delegate Methods
- (void)textViewDidBeginEditing:(UITextView *)textView
{
    if (!textView.hasText) {
        [commentContent setContentOffset:CGPointMake(0, 3)];
        commentContent.scrollsToTop = YES;
        self.commentContent.shadeLabel.hidden = NO;
    }
    else{
        self.commentContent.shadeLabel.hidden = YES;
    }
    currentRowNum = 1;
}

- (void)textViewDidChange:(UITextView *)textView
{
    self.commentContent.shadeLabel.hidden = YES;
}

- (void)sendComment{
    if(self.commentType ==1){
        commentContent.text = @"";//清空
        commentContentField.text = @"";
        [self resign];
        return;
    }
    
    
    
    
    if(self.comfirmPress){
        self.comfirmPress(self.commentContent.text,self.beSelect);
        return;
    }
    
    @synchronized(self){
        NSString *str=self.commentContent.text;
        //判断是否按下发送按钮
        if(_isStrNotNull(str)){
            
            
            NSString *strWithoutSpcace =str;
            
            strWithoutSpcace = [strWithoutSpcace stringByReplacingOccurrencesOfString:@"<" withString:@" "];
            strWithoutSpcace = [strWithoutSpcace stringByReplacingOccurrencesOfString:@">" withString:@" "];
            strWithoutSpcace = [strWithoutSpcace stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
            if (!strWithoutSpcace || 0 == [strWithoutSpcace length]) {
                [self showAlertHeaderView:@"先留言后发表"];
                return;
            }
            if (strWithoutSpcace.length > 300) {
                [self showAlertHeaderView:@"您的评论不能多余300个字"];
                return;
            }else{
                [self performSelector:@selector(issueComment:) withObject:strWithoutSpcace];
            }
            
        }else{
            [self showAlertHeaderView:@"先留言后发表"];
            
        }
        
    }
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    NSString *str = self.commentContent.text;
    //判断是否换行
    if(str.length > 0){
        CGSize maxSize = CGSizeMake(10000,5);
        CGSize expectSize = [str sizeWithFont:self.commentContent.font
                            constrainedToSize:maxSize
                                lineBreakMode:NSLineBreakByWordWrapping];
        int needWidth = 0;
        if(currentRowNum == 1)
            needWidth = expectSize.width;
        else
            needWidth = expectSize.width;
        int widthOfRect = self.commentContent.frame.size.width-17;  //17这个数是实际测出来的
        int rowNumOfNeed = [self getNumOfLine:needWidth rectWidth:widthOfRect];
        if(currentRowNum <= 3 && currentRowNum != rowNumOfNeed){
            //不放大了注释掉
            // [self resetRectOfCommentEditView:rowNumOfNeed];
        }
        else if(currentRowNum == 3 && rowNumOfNeed >= 3){
            //不放大了注释掉
            // [self scrollToVisible:3];
        }
    }
    
}

#pragma mark - set frame of comment edit view
- (void)resetRectOfCommentEditView:(int) rowNumOfNeed
{
    switch (rowNumOfNeed) {
        case 1:                    //默认就有一行
            [self performSelector:@selector(resetRectWhenOneLine)];
            [self scrollToVisible:1];
            break;
        case 2:
            [self performSelector:@selector(resetRectWhenTwoLine)];     //显示2行
            [self scrollToVisible:2];
            break;
        case 3:
            [self performSelector:@selector(resetRectWhenThreeLine)];   //显示3行
            [self scrollToVisible:3];
            break;
        default:
            break;
    }
    currentRowNum = rowNumOfNeed>3?3:rowNumOfNeed;
    self.commentContent.textAlignment = NSTextAlignmentLeft;
}

- (void)scrollToVisible:(int) rowNum    //在缩行时，文字会没有显示在可见区域的中间，所以需要滚动一下
{
    if(rowNum == 1){
        [self.commentContent scrollRectToVisible:self.commentContent.frame animated:YES];
    }
    else if(rowNum == 2){
        [self.commentContent scrollRectToVisible:self.commentContent.frame animated:YES];
    }
    else if(rowNum == 3){
        float origin_y = self.commentContent.contentSize.height - self.commentContent.frame.size.height-8;
        CGRect visibleRect = CGRectMake(0, origin_y, self.commentContent.frame.size.width, self.commentContent.frame.size.height);
        [self.commentContent scrollRectToVisible:visibleRect animated:YES];
    }
    
}

- (void)resetRectWhenOneLine
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationCurve:1.0];
    self.commentDownView.frame = originDownBgFrame;
    self.commentMidView.frame = originMidBgFrame;
    self.commentUpView.frame = originUpBgFrame;
    self.commentContent.frame = CGRectMake(content_Label_x, content_Label_y, content_Label_Width, content_Label_Height);
    [UIView commitAnimations];
}

- (void)resetRectWhenTwoLine
//当评论内容为2行时,重新设置创建评论的框的大小，这个位置不好计算规律，每次变化时，单独写，不和3行的一起
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationCurve:1.0];
    CGRect newFrame = CGRectMake(content_Label_x,
                                 content_Label_y-content_Label_Height,
                                 content_Label_Width,
                                 content_Label_Height*2);
    
    CGRect upViewFrame = CGRectMake(self.commentUpView.frame.origin.x,
                                    newFrame.origin.y-self.commentUpView.frame.size.height,
                                    self.commentUpView.frame.size.width,
                                    self.commentUpView.frame.size.height);
    
    CGRect midViewFrame = CGRectMake(self.commentMidView.frame.origin.x,
                                     newFrame.origin.y,
                                     self.commentMidView.frame.size.width,
                                     newFrame.size.height+2);
    
    [self.commentContent scrollRectToVisible:self.commentContent.frame animated:YES];
    self.commentMidView.frame = midViewFrame;
    self.commentUpView.frame = upViewFrame;
    self.commentContent.frame = newFrame;
    [UIView commitAnimations];
    NSString* contents = self.commentContent.text;
    self.commentContent.text =@"";
    self.commentContent.text = contents;
}

- (void)resetRectWhenThreeLine  //当评论内容为3行时,重新设置创建评论的框的大小，
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationCurve:1.0];
    CGRect newFrame = CGRectMake(content_Label_x,
                                 content_Label_y - content_Label_Height*2+10,
                                 content_Label_Width,
                                 content_Label_Height*3-10);
    
    CGRect upViewFrame = CGRectMake(self.commentUpView.frame.origin.x,
                                    newFrame.origin.y-self.commentUpView.frame.size.height,
                                    self.commentUpView.frame.size.width,
                                    self.commentUpView.frame.size.height);
    
    CGRect midViewFrame = CGRectMake(self.commentMidView.frame.origin.x,
                                     newFrame.origin.y,
                                     self.commentMidView.frame.size.width,
                                     newFrame.size.height+2);
    
    self.commentContent.frame = newFrame;
    CGRect visibleRect = CGRectMake(self.commentContent.frame.origin.x,self.commentContent.contentOffset.y+5,
                                    self.commentContent.frame.size.width,self.commentContent.frame.size.height);
    self.commentMidView.frame = midViewFrame;
    self.commentUpView.frame = upViewFrame;
    [UIView commitAnimations];
    NSString* contents = self.commentContent.text;
    self.commentContent.text =@"";
    self.commentContent.text = contents;
    [self.commentContent scrollRectToVisible:visibleRect animated:YES];
}

- (int)getNumOfLine:(int) width  rectWidth:(int) rectWidth
{
    int rowNum = 0;
    int mode = (int)width/rectWidth;   //模
    int complement = width%rectWidth;  //余数
    if(complement >= 0)
        rowNum = mode + 1;
    else
        rowNum = mode;
    return rowNum;
}

- (void)putCommentViewOriginal
{
    self.commentContent.frame = CGRectMake(content_Label_x, content_Label_y, content_Label_Width, content_Label_Height);
    self.commentContentField.frame = CGRectMake(content_Label_x, content_Label_y, content_Label_Width, content_Label_Height);
    self.commentMidView.frame = originMidBgFrame;
    self.commentDownView.frame = originDownBgFrame;
    self.commentUpView.frame = originUpBgFrame;
}

#pragma mark -
#pragma mark - 键盘显示、隐藏通知事件
-(void)showKeyboard:(NSNotification *)aNotification{
    self.hidden = NO;
    _pickerView.hidden = YES;
    // updated by HouJia at 20130625
    self.backGroundButton.alpha = 0.0;
    [CLGloble sharedInstance].isShowKeyBord = YES;
    NSDictionary *userInfo = aNotification.userInfo;
    
    //
    // Get keyboard size.
    
    NSValue *beginFrameValue = userInfo[UIKeyboardFrameBeginUserInfoKey];
    CGRect keyboardBeginFrame = [[self k_mainWindow] convertRect:beginFrameValue.CGRectValue fromView:nil];
    
    NSValue *endFrameValue = userInfo[UIKeyboardFrameEndUserInfoKey];
    CGRect keyboardEndFrame = [[self k_mainWindow] convertRect:endFrameValue.CGRectValue fromView:nil];
    
    //
    // Get keyboard animation.
    
    NSNumber *durationValue = userInfo[UIKeyboardAnimationDurationUserInfoKey];
    NSTimeInterval animationDuration = durationValue.doubleValue;
    
    NSNumber *curveValue = userInfo[UIKeyboardAnimationCurveUserInfoKey];
    UIViewAnimationCurve animationCurve = curveValue.intValue;
    
    //
    // Create animation.
    
    
    
    //    void (^animations)() = ^() {
    //        CGRect rect =keyboardEndFrame;
    //        commentView.frame = CGRectMake(0, rect_m.origin.y-rect.size.height-rect_m.size.height, rect_m.size.width, rect_m.size.height);
    //    };
    
    commentView.frame = CGRectMake(0, keyboardBeginFrame.origin.y-rect_m.size.height, rect_m.size.width, commentView.height);
    
    
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:animationDuration];
    [UIView setAnimationCurve:animationCurve];
    [UIView setAnimationBeginsFromCurrentState:YES];
    CGRect rect =keyboardEndFrame;
    commentView.frame = CGRectMake(0, rect.origin.y-rect_m.size.height, rect_m.size.width, commentView.height);
    self.backGroundButton.alpha = 0.5;
    [UIView commitAnimations];
    
    
    
    //
    // Begin animation.
    
    //    [UIView animateWithDuration:animationDuration
    //                          delay:0.0
    //                        options:animationCurve//(animationCurve << 16)
    //                     animations:animations
    //                     completion:NULL];
}
-(void)hiddenKeyboard:(NSNotification *)info{
    
    [CLGloble sharedInstance].isShowKeyBord = NO;
    // updated by HouJia at 20130625
    if (!self->isUserClose) {
        _pickerView.hidden = NO;
        return;
    }
    [UIView animateWithDuration:0.25 animations:^{
        commentView.frame = CGRectMake(0, rect_m.origin.y, rect_m.size.width, commentView.height);
        self.backGroundButton.alpha = 0.0;
    } completion:^(BOOL finished) {
        [self performSelector:@selector(putCommentViewOriginal)];
        self.hidden = YES;
        [self removeFromSuperview];
    }];
}

- (void)keyboardChange:(NSNotification *)info
{
    
}

//点击背景触发隐藏键盘
-(void)backGroundButtonClick:(id)sender
{
    [_pickerButton setImage:[UIImage imageNamed:@"liveRoom_reporter_add_picker.png"] forState:UIControlStateNormal];
    if(self.canclePress){
        self.canclePress(self.commentContent.text);
    }
    self.param=nil;
    [self resign];
}

#pragma mark -
#pragma mark - 初始化创建view

-(void)createContent:(UIView *)superView
{
    
    self.frame = CGRectMake(0, 0, GlobleWidth, GlobleHeight);
    self.backgroundColor = [UIColor clearColor];
    self.hidden = YES;
    // 这是那个 黑色透明遮罩貌似
    backGroundButton = [UIButton buttonWithType:UIButtonTypeCustom];
    backGroundButton.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
    backGroundButton.backgroundColor = [UIColor blackColor];
    backGroundButton.alpha = 0.5f;
    [backGroundButton addTarget:self action:@selector(backGroundButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    // backGroundButton.hidden = YES;
    [self addSubview:backGroundButton];
    
    UIView *_n = [[UIView alloc] initWithFrame:content_Background_Origin_Rect];
    self.commentView = _n;
    
    
    
    
    UIImageView *commentbg=[[UIImageView alloc] initWithFrame:
                            CGRectMake(0.0f,
                                       content_Background_Origin_Rect.size.height-defaultHeight,
                                       320.0f,
                                       defaultHeight)];
    
    commentbg.image=[UIImage imageNamed:@"comment_send_bg.jpg"];
    UIEdgeInsets insets=UIEdgeInsetsMake(5, 0, 0, 0);
    [commentbg.image resizableImageWithCapInsets:insets];
    
    [self.commentView addSubview:commentbg];
    
    iosVersion= [[UIDevice currentDevice].systemVersion floatValue];
    
    
    CustomTextView *_textView = [[CustomTextView alloc] initWithFrame:CGRectMake(content_Label_x, content_Label_y, content_Label_Width, content_Label_Height)];
    
    self.commentContent = _textView;
    CGRect frame = commentContent.shadeLabel.frame;
    frame.origin.y = 7;
    commentContent.shadeLabel.frame = frame;
    commentContent.shadeLabel.text = @"";
    commentContent.returnKeyType = UIReturnKeyDefault;
    commentContent.backgroundColor = [UIColor whiteColor];
    commentContent.textColor = RGB(0x4b, 0x4b, 0x4b);
    commentContent.font = [UIFont systemFontOfSize:14];
    commentContent.keyboardType =UIKeyboardTypeDefault;
    commentContent.delegate = self;
    commentContent.autocorrectionType = UITextAutocorrectionTypeYes;
    [commentView addSubview:commentContent];
    
    
    [self addSubview:commentView];
    rect_m = commentView.frame;
    
    // 关闭按钮
    UIButton *buttonClose = [UIButton buttonWithType:UIButtonTypeCustom];
    [buttonClose setImageEdgeInsets:UIEdgeInsetsZero];
    buttonClose.backgroundColor = [UIColor clearColor];
    [buttonClose setImage:[UIImage imageNamed:@"comment_cancel_new.png"] forState:UIControlStateNormal];
    [buttonClose setFrame:CGRectMake(2, 0, 60, 45)];
    [self.commentView addSubview:buttonClose];
    [buttonClose addTarget:self action:@selector(backGroundButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    
    // 发送按钮
    UIButton *sendButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [sendButton setImageEdgeInsets:UIEdgeInsetsZero];
    sendButton.backgroundColor = [UIColor clearColor];
    [sendButton setImage:[UIImage imageNamed:@"comment_send_new.png"]
                forState:UIControlStateNormal];
    sendButton.frame = CGRectMake(250-2+10, 0, 60, 45);
    [self.commentView addSubview:sendButton];
    [sendButton addTarget:self action:@selector(sendComment) forControlEvents:UIControlEventTouchUpInside];
    
    UILabel *title=[[UILabel alloc] initWithFrame:
                    CGRectMake(137.0f, 14.0f, 41.0f, 21.0f)];
    
    title.font=[UIFont systemFontOfSize:18.0f];
    title.textColor=[UIColor blackColor];
    title.backgroundColor=[UIColor clearColor];
    title.text=self.name;
    [self.commentView addSubview:title];
    
    if (_isShowShare) {
        [self createShareView];
    }
    
    if(self.isShowLine){
        float linkButtonY = (content_Label_y+content_Label_Height);
        self.linkButton=[UIButton buttonWithType:UIButtonTypeCustom];
        self.linkButton.frame=CGRectMake(180.0f, self.commentView.height-(defaultHeight-(linkButtonY+3))+20,
                                         GlobleWidth-181.0f, defaultHeight-(linkButtonY+3));
        self.linkButton.titleLabel.font=[UIFont systemFontOfSize:10.0f];
        UIColor *color=[UIColor grayColor];
        [self.linkButton setTitleColor:color forState:UIControlStateNormal];
        [self.linkButton setTitle:@"请您发表正知正见" forState:UIControlStateNormal];
        [self.linkButton handleControlEvent:UIControlEventTouchUpInside withBlock:^(id sender){
            [self resign];
            //        NSString *url=[NSString stringWithFormat:
            //                       [[Globle shareInstance] getAbsolutlyUrlById:@"docFromShare"],@"74978169"];
            //        [DispatchCenter push:@{@"type":@"doc",@"url":url}];
            
            
            
        }];
        [self.commentView addSubview:self.linkButton];
        
        
        
        
    }
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showKeyboard:) name:UIKeyboardWillShowNotification object:nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(hiddenKeyboard:) name:UIKeyboardWillHideNotification object:nil];
    
    
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardChange:) name:UIKeyboardWillChangeFrameNotification object:nil];
    
    
    if(self.isShowShare){
    UILabel *sharelabel=[[UILabel alloc] init];
    sharelabel.font=[UIFont systemFontOfSize:13];
    sharelabel.textColor=RGB(0x99, 0x99, 0x99);
    sharelabel.text=@"同时分享到:";
    sharelabel.frame=CGRectMake(15, self.commentView.height-62, 100, 45);
    [self.commentView addSubview:sharelabel];
    
    
    
    UIView *sharePanel=[[UIView alloc] init];
    sharePanel.frame=CGRectMake(90, self.commentView.height-62, 205.f, 45);
    //sharePanel.backgroundColor=[UIColor orangeColor];
    [self.commentView addSubview:sharePanel];
    NSArray *icons=@[@"tb_weixin.png",@"tb_pengyou.png",@"tb_sina.png",@"tb_qq.png"];
    for(int i=0;i<4;i++){
        UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
        button.tag=i;
        [button setImage:[UIImage imageNamed:icons[i]] forState:UIControlStateNormal];
        button.frame=CGRectMake(i*(45+10), 2, 40, 40);
        [button addTarget:self action:@selector(selectShre:) forControlEvents:UIControlEventTouchUpInside];
        [sharePanel addSubview:button];
    }
    self.select=[[UIImageView alloc] initWithFrame:CGRectMake(26, 26, 14, 14)];
    self.select.image=[UIImage imageNamed:@"comment_share_select.png"];
    }else{
        self.commentContent.height=self.commentContent.height+35;
    }
    if (_isShowImagePicker) {
        _pickerButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_pickerButton setFrame:CGRectMake(self.commentContent.frame.origin.x+self.commentContent.frame.size.width-24.0, self.commentContent.frame.origin.y+self.commentContent.frame.size.height+14.0, 24.0, 22.0)];
        [_pickerButton setImage:[UIImage imageNamed:@"liveRoom_reporter_add_picker.png"] forState:UIControlStateNormal];
        [self.commentView addSubview:_pickerButton];
        [_pickerButton addTarget:self action:@selector(didSelectedPicker:) forControlEvents:UIControlEventTouchUpInside];
        
        _pickerView = [[UIView alloc] initWithFrame:CGRectMake(0, self.frame.size.height-300.0, 320.0, 300.0)];
        _pickerView.backgroundColor = [UIColor whiteColor];
        [self insertSubview:_pickerView belowSubview:commentView];
        _pickerView.hidden = YES;
        
        UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, _pickerView.frame.size.height-216, 320.0, 216) style:UITableViewStylePlain];
        tableView.delegate = self;
        tableView.dataSource = self;
        tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
        tableView.separatorColor = RGB(0xd2, 0xd2, 0xd2);
        tableView.scrollEnabled = NO;
        [_pickerView addSubview:tableView];
    }
}

- (void)selectShre:(UIButton *)button{
    [self.select removeFromSuperview];
    [button addSubview:self.select];
    self.beSelect=button.tag+1;
}
-(void)createShareView{
    
}
-(void)didSelectedshareBtn:(UIButton *)sender{
    
}
- (void)didSelectedPicker:(UIButton *)sender
{
    [self resignWithRemoveView:NO];
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 4;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 216.0/4;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"IFInputViewCell";
    IFInputViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[IFInputViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    
    NSArray *array = @[@"拍照",@"从相册选择图片",@"摄像",@"从相册选择视频"];
    [cell.pickerLabel setText:array[indexPath.row]];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:[tableView indexPathForSelectedRow] animated:YES];
    // [self userSelectPickerWithType:indexPath.row];
}



@end
